﻿using System.Collections;
using System.Drawing;
using System.Runtime.InteropServices.JavaScript;
using System.Xml.Serialization;
using static System.Net.Mime.MediaTypeNames;

namespace 程序文件路径
{
    internal class Program
    {
        static void Main(string[] args)
        {
            SetunaOption optSetuna;
            var text = SetunaOption.ConfigFile;
            Console.WriteLine(text);

            if (!File.Exists(text))
            {
                // 如果文件不存在，则创建它  
                using (FileStream fs = File.Create(text))
                {
                    Console.WriteLine("文件已被创建。");
                }
            }
            else
            {
                Console.WriteLine("文件已被创建。");

                var allType = SetunaOption.GetAllType();
                var xmlSerializer = new XmlSerializer(typeof(SetunaOption), allType);
                var fileStream = new FileStream(text, FileMode.Open);
                optSetuna = (SetunaOption)xmlSerializer.Deserialize(fileStream);
                fileStream.Close();
            }

            Console.WriteLine("Hello, World!");
        }
    }


    public class SetunaOption : ICloneable
    {
        public object Clone()
        {
            throw new NotImplementedException();
        }

        public static string ConfigFile
        {
            get
            {
                // 获取程序的运行路径
                // D:\WORK_SPACE\learn-language\NETCore\日积月累\程序文件路径\程序文件路径\bin\Debug\net8.0
                // var text = AppDomain.CurrentDomain.BaseDirectory; 
                // D:\WORK_SPACE\learn-language\NETCore\日积月累\程序文件路径\程序文件路径\bin\Debug\net8.0
                var text = Environment.CurrentDirectory; 
                Console.WriteLine(text);
                text = Path.GetFullPath(Path.Combine(text, ""));
                Console.WriteLine(text);
                if (!Directory.Exists(text))
                {
                    Directory.CreateDirectory(text);
                }
                // 组合基目录和子目录或文件
                // D:\WORK_SPACE\learn-language\NETCore\日积月累\程序文件路径\程序文件路径\bin\Debug\net8.0\SetunaConfig.xml
                return Path.Combine(text, "SetunaConfig.xml");
            }
        }

        public static Type[] GetAllType()
        {
            var styleType = StyleItemDictionary.GetStyleType();
            var arrayList = new ArrayList {  
                typeof(SetunaOption),
                typeof(Color)
            };
            for (var i = 0; i < styleType.Length; i++)
            {
                arrayList.Add(styleType[i]);
            }
            var array = new Type[arrayList.Count];
            for (var j = 0; j < arrayList.Count; j++)
            {
                array[j] = (Type)arrayList[j];
            }
            return array;
        }
    }

    public class StyleItemDictionary
    {
        protected StyleItemDictionary()
        {
        }

        public static CStyleItem[] GetAllStyleItems()
        {
            return new List<CStyleItem>
            {
                new CMoveStyleItem(),
                new CScaleStyleItem(),
            }.ToArray();
        }

        public static Type[] GetStyleType()
        {
            var list = new List<Type>();
            var allStyleItems = StyleItemDictionary.GetAllStyleItems();
            for (var i = 0; i < allStyleItems.Length; i++)
            {
                list.Add(allStyleItems[i].GetType());
            }
            return list.ToArray();
        }
    }



    public abstract class CStyleItem 
    {
        public CStyleItem()
        {
        }

        public override string ToString()
        {
            return GetDisplayName();
        }

        public abstract string GetDisplayName();
    }


    public class CMoveStyleItem : CStyleItem
    {
        public override string GetDisplayName()
        {
            return "参考图的移动";
        }
    }

    public class CScaleStyleItem : CStyleItem
    {
        public override string GetDisplayName()
        {
            return "缩放参考图";
        }
    }


}
